#include<iostream>

using namespace std;
const int N = 1e3 + 10;
int a[N][N], b[N][N];
int main()
{
    int ra, ca; cin >> ra >> ca;
    for (int i = 1; i <= ra; i++)
    {
        for (int j = 1; j <= ca; j++)
        {
            cin >> a[i][j];
        }
    }
    int rb, cb; cin >> rb >> cb;
    if (rb != ca) 
    {
        cout << "Error: " << ca << " != " << rb << endl;
        return 0;
    }
    for (int i = 1; i <= rb; i++)
        for (int j = 1; j <= cb; j++)
            cin >> b[i][j];
    
    // cout << endl << endl;
    cout << ra << " " << cb << endl;
    for (int i = 1; i <= ra; i++)
    {
        for (int k = 1; k <= cb; k++)
        {
            int sum = 0;
            for (int j = 1; j <= rb; j++)
            {
                sum += a[i][j] * b[j][k];
            }

            // zdl:: 这道题就是在这个地方卡了一下格式，在输出的行首不需要打印空格
            if(k==1) cout << sum ;
			else cout <<' '<< sum ;
        }
        cout << endl;
    }
    return 0;
}